package wellness.activities.adapters;

import java.util.Calendar;

import wellness.activities.beans.AgendamentoBean;
import wellness.activities.beans.LoadBeans;
import android.R.color;
import android.R.style;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

public class EstatisticaMesesAdapter extends BaseAdapter {
	
	private String[] meses = new String[] { "Jan", "Fev", "Mar", "Abr", "Mai", "Jun",
			"Jul", "Ago", "Set", "Out", "Nov", "Dez" };
	private Integer[] valores = new Integer[12];
	Context context;

	public EstatisticaMesesAdapter(Context context, int ano) {
		// TODO Auto-generated constructor stub
		this.context = context;
		
		for(AgendamentoBean a : LoadBeans.getAgendamentos()){
			if(a.isPraticou() != null){
				if (a.getInicio().get(Calendar.YEAR) == ano && a.isPraticou()) {
					Integer mes = a.getInicio().get(Calendar.MONTH);
					if(valores[mes] == null){
						valores[mes] = 0;
					}
					valores[mes] = valores[mes] + 1;
				}	
			}
		}
		
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return 12;
	}

	public Object getItem(int p) {
		// TODO Auto-generated method stub
		return null;
	}

	public long getItemId(int p) {
		// TODO Auto-generated method stub
		return p;
	}

	public View getView(int p, View v, ViewGroup vg) {
		FrameLayout base;
		LinearLayout base2 = new LinearLayout(context);
		
		if(v == null){
			base = new FrameLayout(context);
		}else{
			base = (FrameLayout) v;
		}
		
		base2.setOrientation(LinearLayout.VERTICAL);
		
		TextView mes = new TextView(context);
		TextView qt = new TextView(context);
		qt.setTextColor(Color.WHITE);
		
		Integer valor = valores[p] == null?0:valores[p];
		qt.setText(valor.toString());
		
		mes.setTextAppearance(context, style.TextAppearance_Medium);
		mes.setTextColor(Color.WHITE);
		mes.setText(meses[p]);
		
		base2.addView(mes);
		base2.addView(qt);
		base.addView(base2);
		
		return base;
	}
}
